import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { SEntityInfo } from "../../../../Message/BroadCast/SEntityInfo";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { ColorConfig } from "../../resource/ColorConfig";
import { CareerConfig } from "../../resource/CareerConfig";
import { AvatarInfo } from "../../resource/info/AvatarInfo";
import { AvatarType } from "../../resource/info/AvatarType";
import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { PlayerOpRegister } from "../common/menu/PlayerOpRegister";
import { PlayerOpMenuConst } from "../common/menu/PlayerOpMenuConst";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GButton } from "../../../../com/mui/controls/GButton";
//class NearbyPlayerCellRenderer
    
    export  class NearbyPlayerCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.mouseChildren = true;
            this.initStyle();
            this.createChildren();
            return;
        }

        /* internal  */initStyle(): void
        {
            var loc1=GlobalClass.getScaleBitmap("Friend_over", new Object /* flash.geom.Rectangle */(85, 5, 4, 10));
            loc1.width = 260;
            loc1.height = 38;
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", loc1);
            this.setStyle("overSkin", loc1);
            this.setStyle("selectedDownSkin", loc1);
            this.setStyle("selectedOverSkin", loc1);
            this.setStyle("selectedUpSkin", loc1);
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=ResouceConst.getScaleBitmap("SplitLine");
            loc1.width = 260;
            this.addChild(loc1);
            this._headImg = new Object /* flash.display.Bitmap */();
            this._headImg.x = 5;
            this._headImg.y = 7;
            this.addChild(this._headImg);
            this.nameLabel = new GLabel();
            addChild(this.nameLabel);
            this.nameLabel.setSize(98, 22);
            this.nameLabel.x = 30;
            this.nameLabel.y = 9;
            this.nameLabel.mouseEnabled = false;
            this.levelLabel = new GLabel();
            addChild(this.levelLabel);
            this.levelLabel.setSize(30, 22);
            this.levelLabel.x = 110;
            this.levelLabel.y = 9;
            this.levelLabel.mouseEnabled = false;
            this.campLabel = new GLabel();
            addChild(this.campLabel);
            this.campLabel.setSize(30, 22);
            this.campLabel.x = 146;
            this.campLabel.y = 9;
            this.campLabel.mouseEnabled = false;
            this.careerLabel = new GLabel();
            addChild(this.careerLabel);
            this.careerLabel.setSize(76, 22);
            this.careerLabel.x = 177;
            this.careerLabel.y = 9;
            this.careerLabel.mouseEnabled = false;
            this._operMenuSprite = new Object /* flash.display.Sprite */();
            this._operMenuSprite.buttonMode = true;
            this._operMenuSprite.graphics.beginFill(16711680, 0);
            this._operMenuSprite.graphics.drawRect(0, 0, 200, 38);
            this._operMenuSprite.cacheAsBitmap = true;
            this.addChild(this._operMenuSprite);
            this.inviteBtn = ObjCreate.createGButton(Language.getString(62051), 205, 8, 49, 22, this, "ButtonMini");
            this.inviteBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this.inviteBtn.drawNow();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            if (arg1) 
            {
                this._isTeammate = arg1["isTeammate"] as Boolean;
                this._isCross = arg1["isCross"] as Boolean;
                if (this._isTeammate) 
                {
                    this._publicMiniInfo = arg1["player"] as SPublicMiniPlayer;
                }
                else 
                {
                    loc1 = arg1["player"] as SEntityInfo;
                    this._publicMiniInfo = new SPublicMiniPlayer();
                    this._publicMiniInfo.entityId = loc1.entityId;
                    this._publicMiniInfo.camp = loc1.camp;
                    this._publicMiniInfo.career = loc1.career;
                    this._publicMiniInfo.careerEnable = loc1.careerEnable;
                    this._publicMiniInfo.name = loc1.name;
                    this._publicMiniInfo.sex = loc1.sex;
                    this._publicMiniInfo.level = loc1.level;
                    this._publicMiniInfo.online = 1;
                }
                this.nameLabel.htmlText = HTMLUtil.addColor(this._publicMiniInfo.name, "#B1EFFE");
                this.levelLabel.htmlText = HTMLUtil.addColor(this._publicMiniInfo.level + "", "#B1EFFE");
                this.campLabel.htmlText = HTMLUtil.addColor(GameDefConfig.instance.getCampShort(this._publicMiniInfo.camp).name, ColorConfig.instance.getCampColor(this._publicMiniInfo.camp).color);
                if (CareerConfig.instance.getInfoByCode(this._publicMiniInfo.careerEnable)) 
                {
                    this.careerLabel.htmlText = HTMLUtil.addColor(CareerConfig.instance.getInfoByCode(this._publicMiniInfo.careerEnable).name, "#B1EFFE");
                }
                AvatarInfo.getAvatar(this._publicMiniInfo.camp, this._publicMiniInfo.sex, AvatarType.SMALL, this.onAvatarLoaded, this._publicMiniInfo.avatarId);
                if (!this._playerMiniInfo) 
                {
                    this._playerMiniInfo = new PlayerMiniInfo();
                }
                this._playerMiniInfo.miniPlayer = this._publicMiniInfo;
                PlayerOpRegister.Register(this._operMenuSprite, this._playerMiniInfo, PlayerOpMenuConst.NearbyPlayerOpMenu);
            }
            return;
        }

        /* internal  */onAvatarLoaded(arg1: ImageInfo): void
        {
            this._headImg.bitmapData = arg1.bitmapData;
            this._headImg.width = 22;
            this._headImg.height = 22;
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (data) 
            {
                if (this._isCross || this._isTeammate) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGroup_DoInvite, this._publicMiniInfo.entityId, false, true, false));
                }
                else 
                {
                    loc1 = data["player"] as SEntityInfo;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Group_DoInvite, loc1.entityId, false, true, false));
                }
            }
            return;
        }

        public /* override */ set label(arg1: string)
        {
            return;
        }

        /* internal */ /* var */_headImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */nameLabel: GLabel;

        /* internal */ /* var */levelLabel: GLabel;

        /* internal */ /* var */campLabel: GLabel;

        /* internal */ /* var */careerLabel: GLabel;

        /* internal */ /* var */_operMenuSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */inviteBtn: GButton;

        /* internal */ /* var */_isTeammate: Boolean;

        /* internal */ /* var */_isCross: Boolean;

        /* internal */ /* var */_playerMiniInfo: PlayerMiniInfo;

        /* internal */ /* var */_publicMiniInfo: SPublicMiniPlayer;
    }
